<?php
/* ******************************
	Incoming Tasks aJax actions
   ******************************
*/
	include('../../includes/classes/core.php');
	$action 	= $_REQUEST['act'];
	$data 		= '';
	$error		= '';
	$start		= $_REQUEST['start'];
    $end		= $_REQUEST['end'];
    $client_id	= $_REQUEST['id'];
		
	switch ($action) {
	    case 'get_list':
    	    $count = $_REQUEST['count'];
    	    
    	    $rResult = mysql_query("SELECT 	printer_parts_type.id,
    	                                    production.`name`,
                            				printer_parts_type.`name`,
                            				tbc.price AS tbc,
                            				res.price AS res,
                            				prb.price AS prb,
                            				con.price AS con,
                            				ktg.price AS ktg
                            FROM		printer_pricelist
                            JOIN 		printer_parts_type ON printer_pricelist.parts_type = printer_parts_type.id
                            JOIN 		production ON printer_pricelist.production_id = production.id
                            LEFT JOIN	printer_pricelist AS tbc ON tbc.parts_type=printer_parts_type.id AND production.id =tbc.production_id AND tbc.client_id=11
                            LEFT JOIN	printer_pricelist AS res ON res.parts_type=printer_parts_type.id AND production.id =res.production_id AND res.client_id=12
                            LEFT JOIN	printer_pricelist AS prb ON prb.parts_type=printer_parts_type.id AND production.id =prb.production_id AND prb.client_id=13
                            LEFT JOIN	printer_pricelist AS con ON con.parts_type=printer_parts_type.id AND production.id =con.production_id AND con.client_id=14
                            LEFT JOIN	printer_pricelist AS ktg ON ktg.parts_type=printer_parts_type.id AND production.id =ktg.production_id AND ktg.client_id=126");
			
			$output = array(
				"aaData"	=> array()
			);
			
			while ( $aRow = mysql_fetch_array( $rResult ) )
			{
				$row = array();
				for ( $i = 0 ; $i < $count ; $i++ )
				{
					/* General output */
					$row[] = $aRow[$i];
				}
				$output['aaData'][] = $row;
			}
			
			echo json_encode( $output );

	        break;	    
	    default:
	       	echo "null";
	}
?>